package com.lj.back.manage.scaffold.module.job.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lj.back.manage.scaffold.common.response.R;
import com.lj.back.manage.scaffold.module.job.DTO.ScheduleJobLogDTO;
import com.lj.back.manage.scaffold.module.job.DTO.ScheduleJobLogPageQuery;
import com.lj.back.manage.scaffold.module.job.DTO.ScheduleJobLogStatisticsDTO;
import com.lj.back.manage.scaffold.module.job.service.ScheduleJobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 定时任务日志
 * @author lv
 */
@RestController
@RequestMapping("/schedule/log")
@Api(tags = "定时任务模块")
@ApiSupport(author = "lv")
@AllArgsConstructor
public class ScheduleJobLogController {

	private final ScheduleJobLogService scheduleJobLogService;

	@GetMapping("/list")
    @ApiOperation(value = "分页查询定时任务日志列表")
    @ApiOperationSupport(order = 6)
    @RequiresPermissions("sys:job:log:list")
	public R<IPage<ScheduleJobLogDTO>> list(@Validated ScheduleJobLogPageQuery pageQuery){
        IPage<ScheduleJobLogDTO> scheduleJobLogDTOPage = scheduleJobLogService.listScheduleJobLog(pageQuery);
        return R.success(scheduleJobLogDTOPage);
	}

    @GetMapping("/listStatistics")
    @ApiOperation(value = "查询定时任务统计信息")
    @ApiOperationSupport(order = 7)
    @ApiImplicitParam(name = "jobId", value = "定时任务ID", example = "1", dataTypeClass = Long.class)
    @RequiresPermissions("sys:job:log:statistics")
    public R<List<ScheduleJobLogStatisticsDTO>> listStatistics(String jobId){
        List<ScheduleJobLogStatisticsDTO> scheduleJobLogStatisticsDTOS = scheduleJobLogService.listScheduleJobLogStatistics(jobId);
        return R.success(scheduleJobLogStatisticsDTOS);
    }
}
